package com.yang.controller;


import com.yang.mapper.AreaMapper;
import com.yang.mapper.VaccineMapper;
import com.yang.pojo.Area;
import com.yang.pojo.ResultBody;
import com.yang.pojo.dto.ChinaCity;
import com.yang.pojo.dto.CityAndNum;
import com.yang.service.AreaService;
import com.yang.service.EpidemicService;
import com.yang.service.GdpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YangZhou
 * 2021-09-27-13:06
 */

@RestController
public class VaccineController {

    @Autowired
    private VaccineMapper vaccineMapper;

    @Autowired
    private AreaMapper areaMapper;


    private EpidemicService epidemicService;

    @Autowired
    private AreaService areaService;

    @Autowired
    private GdpService gdpService;


    @GetMapping("/areaEpidemic")

    @ResponseBody
    @CrossOrigin(origins = "*",maxAge = 3600)
    public ResultBody selectCityAndArea(){

        List<Area> areaList = new ArrayList<Area>();


        for (int i = 1; i <= 6;i++) {
            Area area = areaMapper.getAreaById(i);
            areaList.add(area);
        }

        Area area = areaMapper.getAreaById(1);

        for (int i = 1; i < 7;i++) {
             area = areaService.getAreaById(i);
            areaList.add(area);
        }

      area = areaService.getAreaById(1);

        ChinaCity chinaCity = new ChinaCity("中国",areaList);

        Map<String, Object> map = new HashMap<>();
        map.put("AreaVaccine",chinaCity);
        return ResultBody.ok().data(map);
    }

    @GetMapping("/cityEpidemic")
    @ResponseBody
    @CrossOrigin(origins = "*",maxAge = 3600)
    public ResultBody selectAllCity(){


        List<CityAndNum> cityAndNums = vaccineMapper.queryAll();

       // List<CityAndNum> cityAndNums = epidemicService.queryAll();


        return ResultBody.ok().data("cityEpidemic",cityAndNums);
    }

    @GetMapping("/gdp2018")
    @ResponseBody
    @CrossOrigin(origins = "*",maxAge = 3600)
    public ResultBody selectGdp2018() {

        Map<String, Object> map = new HashMap<>();

        String[] cities = gdpService.queryAllName();
        int[] nums = gdpService.queryGdp2018();

        map.put("省份",cities);
        map.put("GDP",nums);

        return ResultBody.ok().data(map);

    }





}
